package com.omuo.utils.collection.demo.simple;

import com.omuo.utils.collection.facade.Mapping;
import com.omuo.utils.collection.facade.StandardMap2BeanProcessorImpl;
import com.omuo.utils.collection.facade.StandardMappingImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 示例测试
 *
 * @author omuao
 */
public class DemoTest {

    public static void main(String[] args) {

        List<Mapping<Object, String>> mappings = new ArrayList<>();

        mappings.add(new StandardMappingImpl(0, "name"));

        mappings.add(new StandardMappingImpl("sex", "sex"));

        mappings.add(new StandardMappingImpl("code", "code"));

        Map<Object, Object> map = new HashMap<>(20);

        map.put(0, "张三");

        map.put("sex", 1);

        map.put("code", "Test");

        StandardMap2BeanProcessorImpl standardMap2BeanProcessor = new StandardMap2BeanProcessorImpl();
        standardMap2BeanProcessor.setMappings(mappings);
        standardMap2BeanProcessor.setOutBeanClass(Demo2Bean.class);
        standardMap2BeanProcessor.setInObjectMap(map);
        standardMap2BeanProcessor.complete();
        System.out.println(standardMap2BeanProcessor.getOutBean());

        Demo2Bean demo2Bean = StandardMap2BeanProcessorImpl.map2Bean(map, mappings, Demo2Bean.class);
        System.out.println(demo2Bean);

        Map<Object, Object> map2 = new HashMap<>(20);

        map2.put(0, "李四");

        map2.put("sex", 0);


        List<Map<? super Object, ? super Object>> list = new ArrayList<>();
        list.add(map);
        list.add(map2);

        List<Demo2Bean> demo2Beans = StandardMap2BeanProcessorImpl.listMap2ListBean(list, mappings, Demo2Bean.class);

        System.out.println(demo2Beans);

    }
}
